class Solution:
    ## 超时
    def lastRemaining(self, n: int, m: int) -> int:
        pos = 0
        arr = [i for i in range(n)]

        while len(arr)>1:
            tmp = (pos+m-1) % len(arr)
            arr.pop(tmp)
            pos = tmp
        return arr[0]